There is afilein your folder called `README`, you should additto your staging area Note: You starteach level withanew repo. Don't look for files from the previous one.
1
gitadd README
第4关
1 2 3 4 5
Name: commit Level: 4 Difficulty: *
The `README` file has been added to your staging area, now commit it.
1
git commit -m'add README'
第5关
1 2 3 4 5
Name: clone Level: 5 Difficulty: *
Clonethe repository at https://github.com/Gazler/cloneme.
1
git clonehttps://github.com/Gazler/cloneme
第6关
1 2 3 4 5
Name: clone_to_folder Level: 6 Difficulty: *
Clone the repository athttps://github.com/Gazler/cloneme to `my_cloned_repo`.
The text editor 'vim' creates files ending in `.swp` (swap files) for all files that are currently open. We don't want them creeping into the repository. Make this repository ignore `.swp` files.
1 2
touch .gitignore echo '*.swp' > .gitignore
第8关
1 2 3 4 5
Name: include Level: 8 Difficulty: **
Notice a few fileswiththe'.a' extension. We want git to ignore all but the'lib.a'file.
There are some filesin this repository, how many ofthefiles will be committed?
1
git status
第11关
1 2 3 4 5
Name: rm Level: 11 Difficulty: **
A file has been removed fromthe working tree, however thefile was not removed fromthe repository. Find out what this file was and remove it.
1 2
gitstatus gitrmdeleteme.rb
第12关
1 2 3 4 5
Name: rm_cached Level: 12 Difficulty: **
A file has accidentally been added to your staging area, find out which fileand remove itfromthe staging area. *NOTE* Do not remove thefilefromthefilesystem, only from git.
1
git rm --cached deleteme.rb
第13关
1 2 3 4 5
Name: stash Level: 13 Difficulty: **
You've made some changes and want to work on them later. You should save them, but don't commit them.
1
git stash
第14关
1 2 3 4 5
Name: rename Level: 14 Difficulty: ***
We have afile called `oldfile.txt`. We want torenameitto `newfile.txt` and stage this change.
1
gitmvoldfile.txtnewfile.txt
第15关
1 2 3 4 5
Name: restructure Level: 15 Difficulty: ***
You added some filesto your repository, but now realize that your project needs to be restructured. Make anewfolder named `src` andusing Git move all ofthe .html filesinto this folder.
1 2
mkdir src git mv *.html src
第16关
1 2 3 4 5
Name: log Level: 16 Difficulty: **
You will be asked forthe hash of most recent commit. You will need to investigate the logs ofthe repository for this.
1
git log
第17关
1 2 3 4 5
Name: tag Level: 17 Difficulty: **
We have a git repo and we want to tag the current commit with `new_tag`.
1
git tagnew_tag HEAD // 默认是HEAD,可以省略
第18关
1 2 3 4 5 6 7 8 9
Name: push_tags Level: 18 Difficulty: **
There are tags in the repository that aren't pushed into remote repository. Push them now.
From /var/folders/3t/kh85db8d1c39qhjhx_h0nxx00000gn/T/d20160215-3639-161bq0y/ * [new branch] master-> origin/master
1
gitpush origin master
第19关
1 2 3 4 5
Name: commit_amend Level: 19 Difficulty: **
The `README` file has been committed, but it looks like thefile `forgotten_file.rb` was missing fromthe commit. Add thefileand amend your previous commit toincludeit.
1 2
git add forgotten_file.rb git commit --amend
第20关
1 2 3 4 5
Name: commit_in_future Level: 20 Difficulty: **
Commit your changes with the future date (e.g. tomorrow).
There are twofilesto be committed. The goal was toaddeachfileasa separate commit, however both were added by accident. Unstage thefile `to_commit_second.rb` usingthe reset command (don't commit anything).
1
git resetHEAD to_commit_second.rb
第22关
1 2 3 4 5
Name: reset_soft Level: 22 Difficulty: **
You committed too soon. Now you want to undo thelast commit, while keeping the index.
1
git reset--soft HEAD^
第23关
1 2 3 4 5
Name: checkout_file Level: 23 Difficulty: ***
A file has been modified, but you don't want to keep the modification. Checkout the `config.rb` filefromthelast commit.
1
git checkout -- config.rb
第24关
1 2 3 4 5
Name: remote Level: 24 Difficulty: **
Thisproject has a remote repository. Identify it.
1
git remote -v
第25关
1 2 3 4 5
Name: remote_url Level: 25 Difficulty: **
The remote repositories have a url associated to them. Please enter the url of remote_location.
1
git remote -v
第26关
1 2 3 4 5
Name: pull Level: 26 Difficulty: **
You need to pull changes from your origin repository.
1
git pull origin master
第27关
1 2 3 4 5
Name: remote_add Level: 27 Difficulty: **
Add a remote repository called `origin` withthe url https://github.com/githug/githug
You have created too many branches for your project. There is an old branch in your repo called 'delete_me', you should deleteit.
1
gitbranch -d delete_me
第37关
1 2 3 4 5
Name: push_branch Level: 37 Difficulty: **
You've made some changes to a local branch and want to share it, but aren't yet ready to merge it with the 'master' branch. Push only 'test_branch' to the remote repository
1
git push origin test_branch:test_branch
第38关
1 2 3 4 5
Name: merge Level: 38 Difficulty: **
We have afileinthe branch 'feature'; Let's merge it to the master branch.
1
git merge feature
第39关
1 2 3 4 5
Name: fetch Level: 39 Difficulty: **
Looks like anew branch was pushed into our remote repository. Get the changes without merging them withthelocal repository
1
git fetch
第40关
1 2 3 4 5
Name: rebase Level: 40 Difficulty: **
We are using a git rebase workflow and the feature branch is ready to go into master. Let's rebase the feature branch onto our master branch.
Your new feature isn't worth thetimeand you're going to delete it. But it has one commit that fills in `README` file, and you want this commit to be onthe master as well.
You have committed several timesbutinthe wrong order. Please reorder your commits.
Hint: Take a look the -i flag of the rebase command.
1
git rebase -i HEAD^^
然后调换两个commit的顺序即可。
第48关
1 2 3 4 5
Name: bisect Level: 48 Difficulty: ***
A bug was introduced somewhere along the way. You know that running `ruby prog.rb 5` should output 15. You can also run `make test`. What are thefirst7charsofthe hash ofthe commit that introduced the bug.
git bisect通过二分查找来帮助查找是哪个commit引入错误。
1 2 3 4 5 6 7
git bisect start // 开始查找 git bisect bad // 标记当前有问题 git bisect good f608824 // 标记第一次提交是没问题的 // 之后git自动会将head指向中间的那个commit ruby prog.rb5// 检测是否有问题 git bisect good // 标记这次提交是没问题的 ...
一直重复,就能找到出错的commit。
第49关
1 2 3 4 5
Name: stage_lines Level: 49 Difficulty: ****
You've made changes within a single filethat belong to two different features, but neither ofthe changes are yet staged. Stage only the changes belonging tothefirst feature.
Hint: 查看git add的说明。
git add -e feature.rb然后删除不想add的变更。
第50关
1 2 3 4 5
Name: find_old_branch Level: 50 Difficulty: ****
You have been working on a branch but got distracted by a major issue and forgot thenameofit. Switch backtothat branch.
使用git reflog来查看是从哪个分支切换过来的。
第51关
1 2 3 4 5 6
Name: revert Level: 51 Difficulty: ****
You have committed several timesbut want to undo themiddle commit. All commits have been pushed, so you can't change existing history.
Hintgit revert
git revert HEAD^
第52关
1 2 3 4 5
Name: restore Level: 52 Difficulty: ****
You decided to delete your latest commitby running `git reset --hard HEAD^`. (Not a smart thing todo.) You thenchange your mind, and want that commit back. Restore the deleted commit.
1 2
git reflog git reset--hard e601101
第53关
1 2 3 4 5
Name: conflict Level: 53 Difficulty: ****
You need to merge mybranch into the current branch (master). But there may be some incorrect changes in mybranch which may cause conflicts. Solve anymerge-conflicts you come across andfinish the merge.
You want toincludethefilesfromthe following repo: `https://github.com/jackmaney/githug-include-me` intoathefolder `./githug-include-me`. Do this without cloning the repo or copying thefilesfromthe repo into this repo.